﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Finances;
@using DCMS.ViewModel.Models.Configuration;

@model TrialBalanceListModel


<section id="content_wrapper">

    <!-- Start: Topbar-Dropdown -->
    <div id="topbar-dropmenu">
        @await Html.PartialAsync("_ToolBox")
    </div>
    <!-- End: Topbar-Dropdown -->
    <!-- Start: Topbar -->
    <header id="topbar">
        <div class="topbar-left">
            <ol class="breadcrumb">
                <li class="crumb-active">
                    <a href="#">财务</a>
                </li>
                <li class="crumb-icon">
                    <a href="@Url.RouteUrl("HomePage")">
                        <span class="glyphicon glyphicon-home"></span>
                    </a>
                </li>
                <li class="crumb-link">
                    <a href="#">财务报表</a>
                </li>
                <li class="crumb-trail">科目余额表</li>
            </ol>
        </div>
        <div class="topbar-right">
            <div class="ml15 ib va-m" id="toggle_sidemenu_r">
                <a href="#" class="pl5">
                    <i class="fa fa-sign-in fs22 text-primary"></i>
                    <span class="badge badge-hero badge-danger">3</span>
                </a>
            </div>
        </div>
    </header>
    <!-- End: Topbar -->
    <!-- Begin: Content -->
    <section id="content" class="formSection">

        <div class="special-alerts">
            <div class="alert alert-danger light alert-dismissable" id="alert-demo-2" style="display: none;">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <i class="fa fa-info pr10"></i>
                <strong>您没有被授权此操作!</strong>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <form asp-action="List" asp-controller="TrialBalance" method="get" id="formSearch" novalidate="novalidate">

                    <div class="panel panel-default" id="panel0">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-search"></span> 高级搜索
                            <a class="btn btn-default btn-sm pull-right m5 mrn p5 pbn" id="AdvancedSearch"><i class="fa fa-angle-double-right"></i></a>
                        </div>
                        <div class="panel-body p10">

                            <div class="row">
                                <div class="col-sm-2">
                                    <dcms-select asp-for="RecordTime" asp-items="@Model.Dates" />
                                </div>
                                <div class="col-sm-10">
                                    <button id="btn_query" type="submit" class="btn btn-primary btn-block">
                                        <span class="glyphicon glyphicon-search mr5" aria-hidden="true"></span>查询
                                    </button>
                                </div>
                            </div>

                        </div>
                    </div>
                </form>
            </div>
        </div>


        <div class="row">
            <div class="col-md-12">

                <div class="panel">
                    <div class="panel-heading">
                        <div class="panel-title">
                            <span class="glyphicon glyphicon-tasks"></span> 余额表
                        </div>
                    </div>
                    <div class="panel-body p10">
                        <div id="toolbar" class="btn-group mb10">
                            <a id="btn_export" class="btn btn-info btn-sm mr5">
                                <span class="glyphicon glyphicon-export mr5"></span>导出
                            </a>
                            <button id="btn_query" type="submit" class="btn btn-alert btn-sm mr5">
                                <span class="glyphicon glyphicon-print mr5" aria-hidden="true"></span>打印
                            </button>
                            <a href="?cache=true" class="btn btn-info btn-sm mr5">
                                <span class="glyphicon glyphicon-refresh mr5"></span>刷新
                            </a>
                           
                        </div>
                        <table class="table table-striped table-bordered table-hover" id="datatable">
                            <tr>
                                <th class="w300 text-left" rowspan="2" width="15%">科目名称</th>
                                <th class="text-right" rowspan="2">科目代码</th>
                                <th class="text-center" colspan="2">期初余额</th>
                                <th class="text-center" colspan="2">本期发生额</th>
                                <th class="text-center" colspan="2">期末余额</th>
                            </tr>
                            <tr>
                                <th class="text-right th-inner pt5 pb5" width="10%">借方</th>
                                <th class="text-right th-inner pt5 pb5" width="10%">贷方</th>
                                <th class="text-right th-inner pt5 pb5" width="10%">借方</th>
                                <th class="text-right th-inner pt5 pb5" width="10%">贷方</th>
                                <th class="text-right th-inner pt5 pb5" width="10%">借方</th>
                                <th class="text-right th-inner pt5 pb5" width="10%">贷方</th>
                            </tr>
                            @foreach (var tree in Model.Trees.OrderBy(s=>s.Option.Code))
                            {

                                <tr>
                                    <td>
                                        @if (tree.Children.Count > 0)

                                        {

                                            <span class="glyphicon glyphicon-chevron-down pl15 mr10"></span>
                                            <a href="@Url.Action("list","ledgerdetails",new {startTime=tree?.Bearer?.PeriodDate.ToString("yyyy-MM-01"),endTime =tree?.Bearer?.PeriodDate.ToString("yyyy-MM-dd"),optionid= tree?.Bearer
                                                    ?.AccountingOptionId })">
                                                @tree.Option.Name
         
                                            </a>

                                        }
                                        else
                                        {
                                            <span class="pl15 mr20"></span>
                                            <a href="@Url.Action("list","ledgerdetails",new {startTime=tree?.Bearer?.PeriodDate.ToString("yyyy-MM-01"),endTime =tree?.Bearer?.PeriodDate.ToString("yyyy-MM-dd"),optionid= tree?.Bearer?.AccountingOptionId })"> @tree?.Option.Name </a>
                                        }
                                    </td>
                                    <td class="text-right"> @tree?.Option.Code</td>

                                    <td class="text-right @((tree.Children.Count > 0)?"text-weight":"")">￥ @((tree?.Bearer?.InitialBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                    <td class="text-right @((tree.Children.Count > 0)?"text-weight":"")">￥ @((tree?.Bearer?.InitialBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                    <td class="text-right @((tree.Children.Count > 0)?"text-weight":"")">￥ @((tree?.Bearer?.PeriodBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                    <td class="text-right @((tree.Children.Count > 0)?"text-weight":"")">￥ @((tree?.Bearer?.PeriodBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                    <td class="text-right @((tree.Children.Count > 0)?"text-weight":"")">￥ @((tree?.Bearer?.EndBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                    <td class="text-right @((tree.Children.Count > 0)?"text-weight":"")">￥ @((tree?.Bearer?.EndBalanceCredit ?? 0).ToString("#,##0.00"))</td>

                                </tr>
                                if (tree.Children.Count > 0)
                                {
                                    foreach (var node in tree.Children)
                                    {
                                        //if (node.Option.Selected)
                                        //{
                                            if (node.Children.Count > 0)
                                            {
                                                <tr>

                                                    @if (node.Children.Count > 0)
                                                    {

                                                        <td><span style="padding-left:60px;" class="glyphicon glyphicon-chevron-down mr10"></span><a href="#"> @node.Option.Name </a></td>
                                                    }
                                                    else
                                                    {
                                                        <td><span style="padding-left:60px;"></span><a href="@Url.Action("list","ledgerdetails",new {startTime=node?.Bearer?.PeriodDate.ToString("yyyy-MM-01"),endTime =node?.Bearer?.PeriodDate.ToString("yyyy-MM-dd"),optionid= node?.Bearer?.AccountingOptionId })">@node.Option.Name</a></td>
                                                    }

                                                    <td class="text-right">@node.Option.Code</td>



                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.InitialBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.InitialBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.PeriodBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.PeriodBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.EndBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.EndBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                </tr>

                                                foreach (var child in node.Children)
                                                {
                                                    if (child.Option.Selected)
                                                    {
                                                        <tr>
                                                            <td>
                                                                <span style="padding-left:100px;"></span>
                                                                <a href="@Url.Action("list","ledgerdetails",new {startTime=node?.Bearer?.PeriodDate.ToString("yyyy-MM-01"),endTime = node?.Bearer?.PeriodDate.ToString("yyyy-MM-dd"),optionid= node?.Bearer?.AccountingOptionId })">
                                                                    @child.Option.Name
                                                                </a>
                                                            </td>
                                                            <td class="text-right"> @child.Option.Code</td>

                                                            <td class="text-right @((child.Children.Count > 0)?"text-weight":"")">￥ @((child?.Bearer?.InitialBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                            <td class="text-right @((child.Children.Count > 0)?"text-weight":"")">￥ @((child?.Bearer?.InitialBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                            <td class="text-right @((child.Children.Count > 0)?"text-weight":"")">￥ @((child?.Bearer?.PeriodBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                            <td class="text-right @((child.Children.Count > 0)?"text-weight":"")">￥ @((child?.Bearer?.PeriodBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                            <td class="text-right @((child.Children.Count > 0)?"text-weight":"")">￥ @((child?.Bearer?.EndBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                            <td class="text-right @((child.Children.Count > 0)?"text-weight":"")">￥ @((child?.Bearer?.EndBalanceCredit ?? 0).ToString("#,##0.00"))</td>


                                                        </tr>
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                <tr>
                                                    @if (node.Children.Count > 0)
                                                    {

                                                        <td>
                                                            <span style="padding-left:60px;" class="glyphicon glyphicon-chevron-down mr10"></span>
                                                            <a href="@Url.Action("list","ledgerdetails",new { startTime = node?.Bearer?.PeriodDate.ToString("yyyy-MM-01"),endTime = node?.Bearer?.PeriodDate.ToString("yyyy-MM-dd"),optionid= node?.Bearer?.AccountingOptionId })"> @node.Option.Name </a>
                                                        </td>
                                                    }
                                                    else
                                                    {
                                                        <td>
                                                            <span style="padding-left:60px;"></span>
                                                            <a href="@Url.Action("list","ledgerdetails",new {startTime=node?.Bearer?.PeriodDate.ToString("yyyy-MM-01"),endTime =node?.Bearer?.PeriodDate.ToString("yyyy-MM-dd"),optionid= node?.Bearer?.AccountingOptionId})">@node.Option.Name</a>
                                                        </td>
                                                    }
                                                    <td class="text-right"> @node.Option.Code</td>

                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.InitialBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.InitialBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.PeriodBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.PeriodBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.EndBalanceDebit ?? 0).ToString("#,##0.00"))</td>
                                                    <td class="text-right @((node.Children.Count > 0)?"text-weight":"")">￥ @((node?.Bearer?.EndBalanceCredit ?? 0).ToString("#,##0.00"))</td>
                                                </tr>
                                            }
                                        //}
                                    }
                                }

                            }
                            <tr>
                                <td colspan="2" class="text-right"><b>总计</b></td>
                                <td class="text-right"><b>￥ @((Model.TotalInitialBalanceDebit ?? 0).ToString("#,##0.00"))</b></td>
                                <td class="text-right"><b>￥ @((Model.TotalInitialBalanceCredit ?? 0).ToString("#,##0.00"))</b></td>
                                <td class="text-right"><b>￥ @((Model.TotalPeriodBalanceDebit ?? 0).ToString("#,##0.00"))</b></td>
                                <td class="text-right"><b>￥ @((Model.TotalPeriodBalanceCredit ?? 0).ToString("#,##0.00"))</b></td>
                                <td class="text-right"><b>￥ @((Model.TotalEndBalanceDebit ?? 0).ToString("#,##0.00"))</b></td>
                                <td class="text-right"><b>￥ @((Model.TotalEndBalanceCredit ?? 0).ToString("#,##0.00"))</b></td>
                            </tr>
                        </table>
                    </div>
                </div>


            </div>
        </div>

    </section>

    <!-- End: Content -->
</section>

@{
//Html.AddCssFileParts(ResourceLocation.Head, "~/assets/skin/default_skin/css/theme.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Toastr/toastr.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Tables/bootstrap-table.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/datepicker/css/bootstrap-datetimepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/daterange/daterangepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/colorpicker/css/bootstrap-colorpicker.min.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/tagmanager/tagmanager.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/fancytree/skin-win8/ui.fancytree.min.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Content/Site.css");
}

@section CurPageScripts
{
    @{
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/utility/jquery.sparkline.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.unobtrusive.js");

//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/jquery.treegrid.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/locale/bootstrap-table-zh-CN.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table-treegrid.js");

//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/globalize.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment-with-locales.js");


//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/daterange/daterangepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/datepicker/js/bootstrap-datetimepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/colorpicker/js/bootstrap-colorpicker.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/jquerymask/jquery.maskedinput.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/tagmanager/tagmanager.js");

//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/fancytree/jquery.fancytree-all.min.js");

//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/admin-tools/admin-forms/js/advanced/steps/jquery.steps.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/admin-tools/admin-forms/js/jquery.validate.min.js");

//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Toastr/Toastr.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Custom/Common.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/bootstrap/holder.min.js");
    }

    <script type="text/javascript">

        jQuery(document).ready(function () {

            "use strict";

            // Init Theme Core
            Core.init();

            // Init Demo JS
            Demo.init();

            //权限提示
            if ($(this).getUrlQueryString("Authorize") == "noAuthorize") {
                $('#alert-demo-2').fadeToggle();
                setTimeout(function () {
                    $('#alert-demo-2').fadeToggle();
                }, 3000);
            }

            //高级搜索
            $("#panel0 #AdvancedSearch").click(function () {
                var ico = $(this).find(".fa");
                if (ico.hasClass('fa-angle-double-right'))
                    ico.removeClass("fa-angle-double-right").addClass("fa-angle-double-down");
                else
                    ico.removeClass("fa-angle-double-down").addClass("fa-angle-double-right");
                $("#panel0").find(".panel-body").toggleClass("hidden fadeIn");
            });

            //防止重复查询
            var queryNumber = 1;
            $("#btn_query").click(function () {
                if (queryNumber > 1) {
                    return false;
                }
                queryNumber = queryNumber + 1;
            });
            //导出
            $("#btn_export").click(function () {
                window.location.href = "/TrialBalance/ExportTrialBalance?RecordTime=" + $("#RecordTime").val();
            });
        });
    </script>
}
